from coin.exchange.base.kr_rest.product import NativeProduct, NormProduct
from coin.exchange.bitfinex_v2.kr_rest.constants import currency_list, quote_currency_list
from coin.exchange.bitfinex_v2.kr_rest.currency import BitfinexCurrency


class BitfinexProduct(NativeProduct):
  _exchange = "Bitfinex"
  NativeCurrencyType = BitfinexCurrency

  def __init__(self, base, quote):
    assert base.currency in currency_list, base
    assert quote.currency in quote_currency_list, quote
    super().__init__(base, quote, "%s%s" % (base.native_symbol, quote.native_symbol))

  @classmethod
  def FromStrNativeProductImpl(cls, product, current_datetime):
    assert isinstance(product, str)
    if len(product) == 6:
      return BitfinexProduct(BitfinexCurrency.FromStrNativeCurrency(product[0:3]),
                             BitfinexCurrency.FromStrNativeCurrency(product[3:6]))
    elif product[0] == 't':
      product = product[1:]
      return BitfinexProduct(BitfinexCurrency.FromStrNativeCurrency(product[0:3]),
                             BitfinexCurrency.FromStrNativeCurrency(product[3:6]))
    raise ValueError('Invalid native product %s' % product)
